package et.six.eta.View;

import android.content.Intent;
import android.os.Handler;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.avos.avoscloud.AVException;
import com.avos.avoscloud.AVObject;
import com.avos.avoscloud.AVUser;
import com.avos.avoscloud.SignUpCallback;

import et.six.eta.MainActivity;
import et.six.eta.R;
import et.six.eta.Util.app.BaseActivity;

public class SignInActivity extends BaseActivity {
    private TransView trv;
    private EditText name;
    private EditText phone;
    private EditText pwd;
    private EditText pwd1;
    public static String static_name;
    public static String static_pwd;
    private TextView have;
    Handler hd = new Handler();
    Runnable r = new Runnable() {
        @Override
        public void run() {
            trv.startAnimation();
        }
    };

    @Override
    protected int getLayoutId() {
        return R.layout.activity_sign;
    }

    @Override
    protected void initView() {
        trv = findViewById(R.id.ani_view);
        name = findViewById(R.id.name);
        phone = findViewById(R.id.phone);
        pwd = findViewById(R.id.pwd);
        pwd1 = findViewById(R.id.pwd1);
        have = findViewById(R.id.have);




    }

    @Override
    protected void initData() {

    }

    @Override
    protected void initListener() {
        trv.setOnAnimationEndListener(new TransView.OnAnimationEndListener() {
            @Override
            public void onEnd() {
                Intent it = new Intent(act, MainActivity.class);
                static_name=name.getText().toString();
                static_pwd=pwd.getText().toString();
                startActivity(it);
                finish();
            }
        });
        have.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent it1 = new Intent(act, LoginActivity.class);
                startActivity(it1);
                Intent it=new Intent(SignInActivity.this, MainActivity.class);
                it.putExtra("name",name.getText().toString());
                it.putExtra("pwd",pwd.getText().toString());
                startActivity(it);

                finish();
            }
        });
    }

    public void signUp(View view) {
        String pw = pwd.getText().toString();
        String pd = pwd1.getText().toString();


        if (pd.equals(pw)) {
           /* AVObject todosign = new AVObject("signinfo");
            todosign.put("name", name.getText().toString());
            todosign.put("email", phone.getText().toString());
            todosign.put("pwd", pwd.getText().toString());
            todosign.saveInBackground();*/
            AVUser user = new AVUser();// 新建 AVUser 对象实例
            user.setUsername(name.getText().toString());// 设置用户名
            user.setPassword(pwd.getText().toString());// 设置密码
            user.setMobilePhoneNumber(phone.getText().toString());
            user.signUpInBackground(new SignUpCallback() {
                @Override
                public void done(AVException e) {
                    if (e == null) {
                        hd.post(r);

                    } else {
                        Toast.makeText(SignInActivity.this, "注册失败"+e.toString(), Toast.LENGTH_SHORT).show();
                    }
                }
            });

        } else {
            hd.removeCallbacksAndMessages(r);
            Toast.makeText(this, "两次密码不一致", Toast.LENGTH_SHORT).show();
        }
    }
}
